package cn.t.web.user;

import cn.t.converter.user.AssignRightsConverter;
import cn.t.core.controller.BaseController;
import cn.t.dto.user.ParticipantAssignRoleRequest;
import cn.t.dto.user.ParticipantInfoDTO;
import cn.t.dto.user.RoleInfoDTO;
import cn.t.dto.user.UserInfoDTO;
import cn.t.facade.user.ParticipantInfoFacade;
import cn.t.facade.user.ParticipantRoleFacade;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 参与者信息表服务入口
 *
 * @author l
 */
@Slf4j
@RestController
@RequestMapping("participantInfo")

@AllArgsConstructor
public class ParticipantInfoController extends BaseController<ParticipantInfoDTO, ParticipantInfoFacade> {



    @PostMapping("/assignRights")
    public Boolean assignRights(@Valid @RequestBody ParticipantAssignRoleRequest request) {

        UserInfoDTO userInfoDTO = assignRightsConverter.toUserInfoDTO(request);
        List<RoleInfoDTO> roleList = assignRightsConverter.toRoleList(request);

        participantRoleFacade.assignRights(userInfoDTO, roleList);

        return true;
    }

    @PostMapping("/bindFirm")
    public Boolean bindFirm(Long userId, Long firmId, Long individualId, Long costCenterId) {
        return facade.bindFirm(userId, firmId, individualId, costCenterId);
    }


    @PostMapping("/unbindFirm")
    public Boolean unbindFirm(Long userId, Long firmId) {
        return facade.unbindFirm(userId, firmId);
    }


    @PostMapping("/bindCostCenter")
    public Boolean bindCostCenter(Long userId, Long costCenterId) {
        return facade.bindCostCenter(userId, costCenterId);
    }

    @PostMapping("/unbindCostCenter")
    public Boolean unbindCostCenter(Long userId, Long costCenterId) {
        return facade.unbindCostCenter(userId, costCenterId);
    }


    @Autowired
    private AssignRightsConverter assignRightsConverter;

    @Autowired
    private ParticipantRoleFacade participantRoleFacade;
}

